package com.abel.bigwater.dataserver.model.hgd

import io.netty.buffer.ByteBuf

/**
 * 02 03 01 01 00
 * 类型 通道号 状态 1 状态 2 状态 3
 * K3 1 1 0
 */
open class KbBaseChannel(type: HgdChannelType, count: Short) : HgdChannel<Byte>(type, count) {
    /**
     * compute length of bytes.
     */
    override fun bufLength() = 2 + count

    override fun parseBuffer(buf: ByteBuf): Boolean {
        super.parseBuffer(buf)

        for (i in 1..count) {
            values.add(buf.readByte())
        }

        return true
    }

    override fun pack(buf: ByteBuf): Boolean {
        super.pack(buf)

        for (i in 1..count) {
            buf.writeByte(values[i].toInt())
        }

        return true
    }

}
